<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<div class="project_contents">
	<h1>Work</h1>
	<div class="project_in">
	<div id="workList_search">
			검색 조건 : 
			<select id="search_type">
				<option value="">-유형-</option>
				<option value="새기능">새기능</option>
				<option value="결함">결함</option>
			</select>
			<select id="search_state">
				<option value="">-상태-</option>
				<option value="신규">신규</option>
				<option value="진행">진행</option>
				<option value="완료">완료</option>
				<option value="거절">거절</option>
			</select>
			<select id="search_priority">
				<option value="">-우선순위-</option>
				<option value="보통">보통</option>
				<option value="낮음">낮음</option>
				<option value="높음">높음</option>
				<option value="즉시">즉시</option>
			</select>
			<select id="search_writer">
				<option value="">-담당자-</option>
			</select>
			<input type="button" id="search_submit" onclick="workList_search();" value="검색" />
	</div>
	<table id="project_table">
		<tr>
			<th>#</th>
			<th>유형</th>
			<th>상태</th>
			<th>우선순위</th>
			<th id="th_title">제목</th>
			<th>담당자</th>
			<th>시작날짜</th>
		</tr>
		<c:set var="date" value="<%=new java.util.Date() %>" />
		<c:forEach items="${workList}" var="work">
			<tr>
				<td>${work.workNo }</td>
				<td>${work.workType }</td>
				<td>${work.workState }</td>
				<td>${work.workPriority }</td>
				<td class="left"><a onclick="work_page(${work.workNo})">${work.workTitle }</a></td>
				<td>${work.name }</td>
				<td>
				<c:choose>
					<c:when test="${work.workStartTime.getMonth() == date.getMonth()
					&& work.workStartTime.getDate() == date.getDate() }">
						<fmt:formatDate value="${work.workStartTime}" pattern="hh:mm:ss" />
					</c:when>
					<c:otherwise>
						<fmt:formatDate value="${work.workStartTime}" pattern="YYYY/MM/dd" />
					</c:otherwise>
				</c:choose>
				</td>
			</tr>
		</c:forEach>
	</table>
	<div id="paging">
	<img id="paging_prev" src="resources/images/page-arrow-left.jpg" />
	<c:forEach var="i" begin="1" end="${(workCount / 10) + 1 }">
		<c:choose>
			<c:when test="${i == pageNum }">
				<a class="onclick"> ${i } </a>
			</c:when>
			<c:otherwise>
				<a id="work_paging_with_num" onclick="work_list_with_num(${i})"> ${i } </a>
			</c:otherwise>
		</c:choose>
	</c:forEach>
	<img id="paging_next" src="resources/images/page-arrow-right.jpg"/>
	</div>
	<script>
		$(document).ready(function(){
			var pageNum = ${pageNum};
			var lastPage =parseInt("${(workCount / 10) + 1 }");
			
			if(pageNum != 1){
				$('#paging_prev').unbind('click');
				
				$('#paging_prev').click(function(){
					work_list_with_num(pageNum-1);
				});
			}
			
			if(pageNum != lastPage){
				$('#paging_next').unbind('click');
				
				$('#paging_next').click(function(){
					work_list_with_num(pageNum+1);
				});
			}
			
			$("#search_type option[value='${search.workType}']").attr("selected", true);
			$("#search_state option[value='${search.workState}']").attr("selected", true);
			$("#search_priority option[value='${search.workPriority}']").attr("selected", true);
			$("#search_writer option[value='${search.writer}']").attr("selected", true);
		});
		
		$.ajax({
			url : "project/createWork/getIdData",
			//				type : "POST",
			cache : false,
			contentType : "application/json; charset=UTF-8",
			success : function(data) {
				var obj = eval(data);
				for( var val in obj){
					
					$('select#search_writer').append("<option value="+obj[val].id+">"+obj[val].name+"</option>");
				}
			}
		});
	</script>
	
	</div>
</div>
